import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-09
 * Time: 22:41
 */
public class Demo1 {
    public  static int count=1;
    public static void main(String[] args) {

        BlockingQueue<Integer> queue=new ArrayBlockingQueue<>(1000);
        Thread t1=new Thread(()->{
            while(true){
                try {
                    queue.put(count);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 生产:"+ count);

                count++;

            }
        });
        Thread t2=new Thread(()->{
            while(true){
                try {
                    int num=queue.take();
                    System.out.println("t2消费:"+num);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        t1.start();
        t2.start();

    }
}
